package main.model;

import y.base.Node;

/**
 * bean represents the condition that an edge appears when given a specific path
 * 
 * @author YuanAn
 *
 */
public class EdgeGivenPath implements OntoEle {
	
	private OntoNodePair edge; //the edge: could be a attribute or relationship
	private OntoPath path; //the given path
	private String name;
	private int edgeCount; //number of edges appearing together with the path
	private double conditionalProb; //the conditional probability of the edge given the path
	
	private int pathCount; //the total number of times a pair of edge and path appears in the training data
	
	
	//the pair of end nodes in the ontology graph
	//private Node[] nodePair;
	
	/**
	 * this creates a dummy conditional prob for edges on all the other paths.
	 */
	public EdgeGivenPath(){
		edge = null;
		path = null;
		name = "::";
		edgeCount = 0;
		pathCount = 0;
		conditionalProb = 0.0;
		
		//nodePair = new Node[2];
	}
	
	public EdgeGivenPath(OntoNodePair e, OntoPath p){
		edge = e;
		path = p;
		name =  path.display() + "::" + edge.display();
		edgeCount = 0;
		pathCount = 0;
		conditionalProb = 0.0;
		
		//nodePair = new Node[2];
	}
	
	
	//getter and setter
	
	public int getEdgeCount(){
		return edgeCount;
	}
	
	public void incrementEdgeCount(){
		edgeCount ++;
	}
	
	public int getPathCount(){
		return pathCount;
	}
	
	public void setPathCount(int c){
		pathCount = c;
	}
	
	public void increasePathCountBy(int diff){
		pathCount += diff;
	}
	
	public void setConditionalProb(double p){
		conditionalProb =  p;
	}
	
	public double getConditionalProb(){
		return conditionalProb;
	}
	
	public OntoNodePair getEdge(){
		return edge;
	}
	
	public OntoPath getPath(){
		return path;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public String display() {
		return name;
	}
	
	
	public String displayPathEdges(){
		String ans = "";
		
		if(path == null)
			return "The likelihood value for all the edges given those paths not appearing in training";
		
		if(edge.getFirstNode() == null || edge.getSecondNode() == null)
			return path.displayEdgePath() + ":: all other edges";
		
		ans += path.displayEdgePath() + "::<" + edge.getFirstNode().toString() + ", " + edge.getSecondNode().toString() + ">"; 
		
		return ans;
	}
	
	
	public Node getFirstNode(){
		return edge.getFirstNode();
	}
	
	public Node getSecondNode(){
		return edge.getSecondNode();
	}
}
